package com.gyt.manager.common.enums;

import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author gyt on 2021/4/28 14:28
 */
@Getter
public enum LabelStateEnum {
    NO(-1, "未知"),
    TO_BE_ONLINE(0, "待上线(草稿中)"),
    CHECKING(1, "自检中"),
    UNCHECKED(2, "自检不通过"),
    IN_APPROVAL(3, "审批中"),
    REJECT(4, "驳回"),
    PILOT_RUN(5, "试运行"),
    ONLINE(6, "已上线"),
    OFFLINE(7, "已下线"),
    IN_ONLINE(8, "上线中");

    private int value;
    private String desc;
    private static final Logger LOGGER =
            LoggerFactory.getLogger(LabelStateEnum.class);

    LabelStateEnum(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 校验.
     *
     * @param val
     * @return
     */
    public static LabelStateEnum check(String val) {
        for (LabelStateEnum anEnum : values()) {
            if (anEnum.getDesc().equals(val)) {
                return anEnum;
            }
        }
        LOGGER.info("LabelStateEnum val:{}", val);
//        throw new BaseException(Response.CODE_ERROR, "labelState有误");
        //由于数据有误，错误数据默认为未知
        return LabelStateEnum.NO;
    }
}
